#!/usr/bin/env python
# encoding: utf-8
'''
@author: 王震
@license: 四川凡狼科技有限公司
@contact: 2668985108@qq.com
@file: classHour.py
@time: 2021/10/1 11:05 下午
@desc:
'''

from flask import Blueprint, request
from app.business.classHour.classHour import add_class_hours, get_class_hour as get, update_class_hour as update, \
    delete_class_hour as delete, system_get_class_hour as st_get, update_show, get_shoe, customer_class_list
from app.public.sqlMethods import auto
from app.public.sqlMethods import set_content_type
from app.msg.resp import response_json
from app.msg.tips import *

classHour = Blueprint('classHour', __name__, url_prefix='/api')

'''
创建课时
'''


@classHour.route('/add/class/hour', methods=['POST'])
@auto.login_required
def add_class_hour():
    data = request.json
    if set_content_type():
        return response_json(code=tips['content_Type'], msg=tipsText['content_Type'])
    return add_class_hours(_dict=data)


'''
获取客户端课程对应的课时
'''


@classHour.route('/get/class/hour', methods=['GET'])
def get_class_hour():
    _id = request.args.get('parentId', None)
    page_number = request.args.get('pageNumber', 1)
    page_size = request.args.get('pageSize', 10)
    return get(page_number=page_number, page_size=page_size, parent_id=_id)


'''
管理系统获取当前课时列表
'''


@classHour.route('/system/get/class/hour', methods=['GET'])
@auto.login_required
def system_get_class_hour():
    page_number = request.args.get('pageNumber', 1)
    page_size = request.args.get('pageSize', 10)
    return st_get(page_number=page_number, page_size=page_size)


@classHour.route('/update/class/hour', methods=['PUT'])
@auto.login_required
def update_class_hour():
    data = request.json
    return update(data=data)


@classHour.route('/update/show/hour', methods=['PUT'])
@auto.login_required
def show_hour():
    data = request.json
    return update_show(data=data)


'''
获取管理系统课时状态列表
'''


@classHour.route('/get/search/list', methods=['GET'])
@auto.login_required
def get_show_list():
    page_number = request.args.get('pageNumber', 1)
    page_size = request.args.get('pageSize', 10)
    _id = request.args.get('parentId', None)
    show = request.args.get('show', 1)
    return get_shoe(page_number=page_number, page_size=page_size, show=show, _id=_id)


@classHour.route('/delete/class/hour', methods=['DELETE'])
@auto.login_required
def delete_class_hour():
    data = request.json
    _id = data['id'] if 'id' in data else None
    return delete(_id=_id)


@classHour.route('/customer/classHour/list')
def customer_class_hour():
    _id = request.args.get('parentId')
    customer_class_list(parent_id=_id)
    return '11111'
